import request from "@/utils/request2";

const DEPT_BASE_URL = "/api/v1/script";

export function getListApi(params) {
    return request({
        url: `${DEPT_BASE_URL}/list`,
        method: "get",
        params,
    });
}

export function getCountApi(params) {
    return request({
        url: `${DEPT_BASE_URL}/count`,
        method: "get",
        params,
    });
}

export function importFormApi(params) {
    return request.post(`${DEPT_BASE_URL}/import`, params, {
      transformRequest: [
        (params) => {
          return params;
        },
      ],
      headers: {
        "Content-Type": "multipart/form-data",
      },
    })
    .then((res) => {
      if (res) return res;
    })
    .catch((err) => {});
}
  
export function getDownloadApi(id) {
    return request({
        url: `${DEPT_BASE_URL}/download/${id}`,
        method: "get",
        responseType: 'blob',
    });
}

export function getUischemaApi(id) {
    return request({
        url: `${DEPT_BASE_URL}/uischema/${id}`,
        method: "get",
    });
}

export function changeScriptApi(name, data) {
    return request({
        url: `${DEPT_BASE_URL}/change/${name}`,
        method: "POST",
        data
    });
}

export function updateInfoApi(params, id) {
    return request.post(`${DEPT_BASE_URL}/update/${id}`, params, {
        transformRequest: [
          (params) => {
            return params;
          },
        ],
        headers: {
          "Content-Type": "multipart/form-data",
        },
      })
      .then((res) => {
        if (res) return res;
      })
      .catch((err) => {});
}

export function deleteByIdsApi(data) {
    return request({
        url: `${DEPT_BASE_URL}/delete`,
        method: "POST",
        data
    });
}

export function deleteByIdApi(id) {
    return request({
        url: `${DEPT_BASE_URL}/delete/${id}`,
        method: "get",
    });
}
